home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / Examples / PrinterClassDriver / PrintDriverShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  4.7 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:            PrintDriverShell.c
  3.  
  4.     Contains:    Driver description and export entry points for Printer Class Driver
  5.  
  6.     Version:        Neptune 1.0
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <MacTypes.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17. #include "PrinterClassDriver.h"
  18. #include "PrinterClassVersion.h"
  19.  
  20. //------------------------------------------------------
  21. //
  22. // Protos
  23. //
  24. //------------------------------------------------------
  25. OSStatus printDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc);
  26. OSStatus printDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  27. OSStatus printDriverInitInterface( UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device);
  28. OSStatus printDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr desc );
  29. OSStatus    printDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon);
  30.  
  31. //------------------------------------------------------
  32. //
  33. //    This is the driver description structure that the expert looks for first.
  34. //  If it's here, the information within is used to match the driver
  35. //  to the device whose descriptor was passed to the expert.
  36. //    Information in this block is also used by the expert when an
  37. //  entry is created in the Name Registry.
  38. //
  39. //------------------------------------------------------
  40.  
  41. USBDriverDescription    TheUSBDriverDescription = 
  42. {
  43.     // Signature info
  44.     kTheUSBDriverDescriptionSignature,
  45.     kInitialUSBDriverDescriptor,
  46.     
  47.     // Device Info
  48.     0,                                        // vendor = not device specific
  49.     0,                                        // product = not device specific
  50.     0,                                        // version of product = not device specific
  51.     0,                                        // protocol = not device specific
  52.     
  53.     // Interface Info    (* I don't think this would always be required...*)                
  54.     0,                                        // Configuration Value
  55.     0,                                        // Interface Number
  56.     kUSBPrintClass,                            // Device Class  (from USBDeviceDefines.h)
  57.     kUSBPrintSubClass,                        // Device Subclass 
  58.     0,                                        // Interface Protocol
  59.         
  60.     
  61.     // Driver Info    
  62.     "\pUSBPrinterDriver"kPrintStringVersShort,// Driver name for Name Registry
  63.     kUSBPrintClass,                            // Device Class  (from USBDeviceDefines.h)
  64.     kUSBPrintSubClass,                        // Device Subclass 
  65.     kPrintHexMajorVers, kPrintHexMinorVers, kPrintReleaseStage, kPrintNonRelRev,        // version of driver
  66.     
  67.     // Driver Loading Info
  68.     0x00000000                                // Flags (currently undefined)
  69. };
  70.  
  71.     
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,            // Version of this structure
  75.     printDriverValidateHW,                // Hardware Validation Procedure
  76.     printDriverInitialize,                // Initialization Procedure
  77.     printDriverInitInterface,            // Interface Initialization Procedure
  78.     printDriverFinalize,                // Finalization Procedure
  79.     printDriverNotifyProc,                // Driver Notification Procedure
  80. };
  81.  
  82. // Hardware Validation
  83. // Called upon load by Expert
  84. OSStatus 
  85. printDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  86. {
  87.     device = 0;
  88.     desc = 0;
  89. //    DebugStr("\pPrinter Driver - printDriverValidateHW");
  90.     return (OSStatus)noErr;
  91. }
  92.  
  93.  
  94. // Initialization function
  95. // Called upon load by Expert
  96. OSStatus 
  97. printDriverInitialize(USBDeviceRef deviceRef, USBDeviceDescriptorPtr pDeviceDesc, UInt32 busPowerAvailable)
  98. {
  99.     busPowerAvailable = 0;
  100.     
  101. //    DebugStr("\pPrinter Driver - printDriverInitialize");
  102.     USBExpertStatus(deviceRef, "\p"kStrPrinterClass"Driver Initialize", 0);
  103.     PrintDriverEntry(deviceRef, pDeviceDesc, NULL, 0 );
  104.     return (OSStatus)noErr;
  105. }
  106.  
  107. // printDriverInitInterface function
  108. // Called to initialize driver for an individual interface - either by expert or
  109. // internally by driver
  110. OSStatus
  111. printDriverInitInterface(
  112.             UInt32                         interfaceNumber, 
  113.             USBInterfaceDescriptor    *pInterfaceDesc, 
  114.             USBDeviceDescriptor        *pDeviceDesc, 
  115.             USBDeviceRef                 interfaceRef)
  116. {
  117.  
  118. //    DebugStr("\pPrinter Driver - printDriverInitInterface");
  119.     USBExpertStatus(interfaceRef, "\p"kStrPrinterClass"Interface Initialize", 0);
  120.     PrintDriverEntry(interfaceRef, pDeviceDesc, pInterfaceDesc, interfaceNumber );
  121.     
  122.     return (OSStatus)noErr;
  123. }
  124.  
  125. // Termination function
  126. // Called by Expert when driver is being shut down
  127. OSStatus
  128. printDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr desc )
  129. {
  130. #pragma unused(device)
  131. #pragma unused(desc)
  132.  
  133. //    DebugStr("\pPrinter Driver - printDriverFinalize");
  134.     return kUSBNoErr;
  135. }
  136.  
  137. OSStatus    
  138. printDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  139. {
  140. #pragma unused(pointer)
  141. #pragma unused(refcon)
  142.  
  143. OSStatus err = kUSBNoErr;
  144.  
  145. //    DebugStr("\pPrinter Driver - printDriverNotifyProc");
  146.     switch (notification)
  147.     {
  148.         case kNotifyDriverBeingRemoved:
  149.             err = PrinterRemovalNotification();
  150.             break;
  151.         
  152.     }
  153.     return(err);
  154. }
  155.